package com.chencong.online.utils;

import org.junit.Test;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @program: user-behavior-analysis-online
 * @ClassName TimestampTransformUtil
 * @description:时间戳转化工具类
 * @author: chencong
 * @create: 2021-12-28 14:23
 **/
public class TimestampTransformUtil {

    /**
     * @return
     * @Author chencong
     * @Description 将毫秒级时间戳转为本地时间(localDataTime)
     * @Date 14:25 2021/12/28
     * @Param
     **/
    public static LocalDateTime milliTimestampToLocalDateTime(Long milliTimestamp) {
        LocalDateTime localDateTime = Instant.ofEpochMilli(milliTimestamp).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
        return localDateTime;
    }


    /**
     * @return
     * @Author chencong
     * @Description 将本地时间转换为毫秒级时间戳
     * @Date 10:15 2021/12/29
     * @Param
     **/
    public static long localDataTimeToMilliTimestamp(LocalDateTime localDateTime) {
        long milliTimestamp = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        return milliTimestamp;
    }

}
